package com.ccb.sc.member.controller;

import com.ccb.sc.auth.TokenAuth;
import com.ccb.sc.auth.TokenModel;
import com.ccb.sc.member.service.DailyTaskService;
import com.ccb.sc.member.vo.DailyTaskVo;
import com.ccb.sc.common.bind.annotation.CurrentUser;
import com.ccb.sc.common.bind.response.ResBody;
import com.ccb.sc.common.modules.member.enums.MemberPointsLogType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * @author ken
 * @version 1.0
 * @date 2020-10-08
 */
@RestController
@RequestMapping("/app/task")
@Api(value = "每日任务", tags = "每日任务")
public class AppTaskController {

    @Autowired
    private DailyTaskService dailyTaskService;

    @TokenAuth
    @GetMapping("/list")
    @ApiOperation(value = "任务列表", response = DailyTaskVo.class, responseContainer = "list")
    public ResBody<?> taskList(@ApiIgnore @CurrentUser TokenModel token) {
        List<DailyTaskVo> dailyTasks = this.dailyTaskService.findDailyTasks(token.getId());
        return ResBody.success(dailyTasks);
    }

    @TokenAuth
    @PostMapping("/award")
    @ApiOperation(value = "分享任务奖励")
    public ResBody<?> award(@ApiIgnore @CurrentUser TokenModel token) {
        int reward = this.dailyTaskService.reward(token.getId(), MemberPointsLogType.SHARE, "");
        return ResBody.success(reward);
    }
}
